package com.voicechat.firstmet.activity;

import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.voicechat.firstmet.R;
import com.voicechat.firstmet.adapter.NoticeAdapter;
import com.voicechat.firstmet.base.BaseActivity;
import com.voicechat.firstmet.bean.CoummunityNotice;
import com.voicechat.firstmet.utils.StatusBarUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ProjectName: FirstMet
 * @Package: com.voicechat.firstmet.activity
 * @ClassName: SystemNotificationActivity
 * @Description: java类作用描述
 * @Author: ljp
 * @CreateDate: 2018/11/16 15:49
 * @Version: 1.0
 */
public class SystemNotificationActivity extends BaseActivity {
    @BindView(R.id.linear_back)
    LinearLayout linearBack;
    @BindView(R.id.recycler_system)
    RecyclerView recyclerSystem;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.linear_notice_details)
    LinearLayout linearNoticeDetails;

    private List<CoummunityNotice.PageBean.ListBean> notices;
    private NoticeAdapter noticeAdapter;
    private String TAG = "SystemNotificationActivity";

    @Override
    protected int setStatusBarColor() {
        return 0;
    }

    @Override
    protected boolean isSettingStatusBarText() {
        return false;
    }

    @Override
    protected int loadLayout() {
        return R.layout.activity_system_notification;
    }

    @Override
    protected void initLayout(Bundle savedInstanceState) {
        ButterKnife.bind(this);
        //透明状态栏
        StatusBarUtils.Full(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        notices = getIntent().getParcelableArrayListExtra("notice");
        Log.i(TAG, "initLayout: ----" + notices.size());
        initView();
    }

    /**
     * @return
     * @method
     * @description 数据控件实例化
     * @date: 2018/11/16 15:55
     * @author: ljp
     */
    private void initView() {
        noticeAdapter = new NoticeAdapter(context, notices, R.layout.item_notice);
        recyclerSystem.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
        recyclerSystem.setAdapter(noticeAdapter);
        noticeAdapter.setItemClick(new NoticeAdapter.ItemClick() {
            @Override
            public void itemNoticeClicek(CoummunityNotice.PageBean.ListBean listBean) {
                recyclerSystem.setVisibility(View.GONE);
                linearNoticeDetails.setVisibility(View.VISIBLE);
                tvTitle.setText(listBean.getTitle());
                tvContent.setText(listBean.getContent());
                tvTime.setText(listBean.getUpdateDate());

            }
        });

    }

    @OnClick(R.id.linear_back)
    public void onClick() {
        if(recyclerSystem.getVisibility() == View.VISIBLE){
            finish();
        }else {
            recyclerSystem.setVisibility(View.VISIBLE);
            linearNoticeDetails.setVisibility(View.GONE);
        }
    }

    @Override
    public void onBackPressed() {
        if(recyclerSystem.getVisibility() == View.VISIBLE){
            super.onBackPressed();
        }else {
            recyclerSystem.setVisibility(View.VISIBLE);
            linearNoticeDetails.setVisibility(View.GONE);
        }
    }
}
